package com.ruoyi.web.controller.declare;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.LhqDeclare;
import com.ruoyi.domain.YcPersonal;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.service.ILhqDeclareService;
import com.ruoyi.service.IYcPersonalService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 申报系统Controller
 * 
 * @author ruoyi
 * @date 2020-10-16
 */
@Controller
@RequestMapping("/ruoyi/declare")
public class LhqDeclareController extends BaseController
{
    private String prefix = "ruoyi/declare";

    @Autowired
    private ILhqDeclareService lhqDeclareService;
    @Resource
    private IYcPersonalService iYcPersonalService;
    @RequiresPermissions("ruoyi:declare:view")
    @GetMapping()
    public String declare()
    {
        return prefix + "/declare";
    }

    /**
     * 查询申报系统列表
     */
    @RequiresPermissions("ruoyi:declare:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LhqDeclare lhqDeclare)
    {
        startPage();
        List<LhqDeclare> list = lhqDeclareService.selectLhqDeclareList(lhqDeclare);
        return getDataTable(list);
    }

    /**
     * 导出申报系统列表
     */
    @RequiresPermissions("ruoyi:declare:export")
    @Log(title = "申报系统", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LhqDeclare lhqDeclare)
    {
        List<LhqDeclare> list = lhqDeclareService.selectLhqDeclareList(lhqDeclare);
        ExcelUtil<LhqDeclare> util = new ExcelUtil<LhqDeclare>(LhqDeclare.class);
        return util.exportExcel(list, "declare");
    }

    /**
     * 新增申报系统
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存申报系统
     */
    @RequiresPermissions("ruoyi:declare:add")
    @Log(title = "申报系统", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LhqDeclare lhqDeclare)
    {
        //赋值关联id
        lhqDeclare.setUserId(ShiroUtils.getUserId());
        //赋值上传作者
        lhqDeclare.setChinappt(ShiroUtils.getLoginName());
        return toAjax(lhqDeclareService.insertLhqDeclare(lhqDeclare));
    }

    /**
     * 修改申报系统
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LhqDeclare lhqDeclare = lhqDeclareService.selectLhqDeclareById(id);
        mmap.put("lhqDeclare", lhqDeclare);
        return prefix + "/edit";
    }

    /**
     * 修改保存申报系统
     */
    @RequiresPermissions("ruoyi:declare:edit")
    @Log(title = "申报系统", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LhqDeclare lhqDeclare)
    {
        return toAjax(lhqDeclareService.updateLhqDeclare(lhqDeclare));
    }

    /**
     * 删除申报系统
     */
    @RequiresPermissions("ruoyi:declare:remove")
    @Log(title = "申报系统", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lhqDeclareService.deleteLhqDeclareByIds(ids));
    }

    /**
    * 第一次提交
    */
    @Log(title = "审批状态", businessType = BusinessType.UPDATE)
    @PostMapping( "/tijiao")
    @ResponseBody
    public AjaxResult tijiao(Long id) {
        LhqDeclare lhqDeclare=new LhqDeclare();
        //赋值当前id
        lhqDeclare.setId(id);
        //更改第一次审批状态
        lhqDeclare.setFirstApprovalStatus(1L);
        //执行修改方法
        lhqDeclareService.updateLhqDeclare(lhqDeclare);
        return success();
    }
    /**
     * 上传开题报告
     */
    @GetMapping("/uploadTheOpeningReport/{id}")
    public String uploadTheOpeningReport(@PathVariable("id") Long id, ModelMap mmap)
    {
        LhqDeclare lhqDeclare = lhqDeclareService.selectLhqDeclareById(id);
        mmap.put("lhqDeclare", lhqDeclare);
        return prefix + "/uploadTheOpeningReport";
    }
    /**
     * 提交开题报告
     */
    @Log(title = "审批状态", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitTheProposalReport")
    @ResponseBody
    public AjaxResult submitTheProposalReport(Long id) {
        LhqDeclare lhqDeclare=new LhqDeclare();
        //赋值当前id
        lhqDeclare.setId(id);
        //更改审批状态
        lhqDeclare.setFirstApprovalStatus(7L);
        //执行修改方法
        lhqDeclareService.updateLhqDeclare(lhqDeclare);
        return success();
    }
    /*
    * 提交中期报告
    * */
    @Log(title = "审批状态", businessType = BusinessType.UPDATE)
    @PostMapping( "/submissionOfInterimReport")
    @ResponseBody
    public AjaxResult submissionOfInterimReport(Long id) {
        LhqDeclare lhqDeclare=new LhqDeclare();
        //赋值当前id
        lhqDeclare.setId(id);
        //更改审批状态
        lhqDeclare.setFirstApprovalStatus(10L);
        //执行修改方法
        lhqDeclareService.updateLhqDeclare(lhqDeclare);
        return success();
    }
    /*
    * 上传中期报告
    * */
    @GetMapping("/uploadInterimReport/{id}")
    public String uploadInterimReport(@PathVariable("id") Long id, ModelMap mmap)
    {
        LhqDeclare lhqDeclare = lhqDeclareService.selectLhqDeclareById(id);
        mmap.put("lhqDeclare", lhqDeclare);
        return prefix + "/uploadInterimReport";
    }
    /*
     * 上传结题报告
     * */
    @GetMapping("/uploadTheFinalReport/{id}")
    public String uploadTheFinalReport(@PathVariable("id") Long id, ModelMap mmap)
    {
        LhqDeclare lhqDeclare = lhqDeclareService.selectLhqDeclareById(id);
        mmap.put("lhqDeclare", lhqDeclare);
        return prefix + "/uploadTheFinalReport";
    }
    /*
     * 提交结题报告
     * */
    @Log(title = "审批状态", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitTheFinalReport")
    @ResponseBody
    public AjaxResult submitTheFinalReport(Long id) {
        LhqDeclare lhqDeclare=new LhqDeclare();
        //赋值当前id
        lhqDeclare.setId(id);
        //更改审批状态
        lhqDeclare.setFirstApprovalStatus(13L);
        //执行修改方法
        lhqDeclareService.updateLhqDeclare(lhqDeclare);
        return success();
    }
    /*
    * 查看作者
    * */
    @GetMapping("/toViewTheAuthor/{userId}")
    public String toViewTheAuthor(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        YcPersonal ycPersonal = iYcPersonalService.selectYcPersonalById(userId);
        System.out.println(ycPersonal);
        mmap.put("ycPersonal", ycPersonal);
        return prefix + "/particularss";
    }
}
